package com.zb.network.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.entity.SelectVo;
import com.zb.result.PageUtil;
import com.zb.result.Result;
import com.zb.service.ZjNetworkEmpLevelService;
import com.zb.utils.TokenUtil;
import com.zb.vo.NetworkEmpLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 网点人员等级表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2024-01-29
 */
@Api(tags = "服务商人员等级类接口")
@RestController
@RequestMapping("/network/emp/level")
public class ZjNetworkEmpLevelController {
    @Resource
    private ZjNetworkEmpLevelService networkEmpLevelService;

    @SystemLog(moduleType = OperationLogModuleType.NETWORK_TYPE, type = OperationLogType.DELETE, remark = "服务区域-服务商设置-工程师等级 - 新增或更新人员等级")
    @ApiOperation("新增或更新人员等级")
    @PostMapping("/save")
    public Result save(HttpServletRequest request, @RequestBody @Valid NetworkEmpLevelVo empLevelVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        networkEmpLevelService.save(custAccId, empLevelVo);
        return Result.success(null == empLevelVo.getId()? "新增人员等级成功" : "修改人员等级成功");
    }

    @ApiOperation("获取人员等级列表")
    @PostMapping("/getList")
    public Result getList(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取人员等级列表成功").data(networkEmpLevelService.getList(custAccId, selectVo));
    }

    @ApiOperation("根据ID获取人员等级详情")
    @GetMapping("/getDetail/{id}")
    public Result getDetail(@PathVariable @ApiParam(value = "人员等级ID", required = true) Long id) {
        return Result.success("获取人员等级详情成功").data(PageUtil.row(networkEmpLevelService.getDetail(id)));
    }

    @SystemLog(moduleType = OperationLogModuleType.NETWORK_TYPE, type = OperationLogType.DELETE, remark = "服务区域-服务商设置-工程师等级 - 批量启用或禁用人员等级")
    @ApiOperation("批量启用或禁用人员等级")
    @PutMapping("/disable")
    public Result disable(@RequestParam @ApiParam(value = "人员等级状态：false-启用，true-禁用", required = true, example = "false") boolean status,
                          @RequestBody @ApiParam(value = "人员等级ID", required = true) List<Long> ids) {
        networkEmpLevelService.updateDisabledBatchById(ids, status);
        return Result.success(status? "禁用人员等级成功" : "启用人员等级成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.NETWORK_TYPE, type = OperationLogType.DELETE, remark = "服务区域-服务商设置-工程师等级 - 根据人员等级ID批量删除")
    @ApiOperation("根据人员等级ID批量删除")
    @DeleteMapping("/delete")
    public Result delete(@RequestBody @ApiParam(value = "人员等级ID", required = true) List<Long> ids) {
        networkEmpLevelService.deleteBatchById(ids);
        return Result.success("删除人员等级成功");
    }

}
